<?php
/**************************************************************************
	ESAM (EVE to SMF API Module)
	Copyright (C) 2009  Sasha J

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/

// If SSI.php is in the same place as this file, and SMF isn't defined, this is being run standalone.
if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
  require_once(dirname(__FILE__) . '/SSI.php');
// Hmm... no SSI.php and no SMF?
elseif (!defined('SMF'))
  die('<b>Error:</b> Cannot install - please verify you put this in the same place as SMF\'s index.php.');

require_once('Sources/EveOnline.php');

// Installs the Database tables for EVE-Online

// Users API Keys Table
db_query("CREATE TABLE IF NOT EXISTS {$db_prefix}eve_api_keys(
ID_KEY int(11) NOT NULL auto_increment,
ID_MEMBER mediumint(8) unsigned NOT NULL default '0',
USER_ID varchar(8) NOT NULL,
API_KEY varchar(64) NOT NULL,
PRIMARY KEY (ID_KEY))", __FILE__, __LINE__);

// Alliances
db_query("CREATE TABLE IF NOT EXISTS {$db_prefix}eve_alliances(
ID_AL int(11) NOT NULL auto_increment,
EVE_NAME varchar(255) NOT NULL,
EVE_ID varchar(20) NOT NULL,
PRIMARY KEY (ID_AL))", __FILE__, __LINE__);

// Corporations
db_query("CREATE TABLE IF NOT EXISTS {$db_prefix}eve_corporations(
ID_CORP int(11) NOT NULL auto_increment,
EVE_NAME varchar(255) NOT NULL,
EVE_ALLIANCE_ID varchar(20) NOT NULL DEFAULT '0',
EVE_ID varchar(20) DEFAULT NULL,
PRIMARY KEY (ID_CORP))", __FILE__, __LINE__);

// Rules table
db_query("CREATE TABLE IF NOT EXISTS {$db_prefix}eve_rules(
ID_RULE int(11) NOT NULL auto_increment,
EVE_ROLE varchar(30) DEFAULT NULL,
EVE_CORP_ID varchar(20) DEFAULT NULL,
EVE_ALLIANCE_ID varchar(20) DEFAULT NULL,
ID_GROUP int(11) NOT NULL,
PRIMARY KEY (ID_RULE))", __FILE__, __LINE__);

// Characters
db_query("CREATE TABLE IF NOT EXISTS {$db_prefix}eve_characters(
ID_CHARACTER int(11) NOT NULL auto_increment,
ID_MEMBER mediumint(8) unsigned NOT NULL default '0',
EVE_CHAR_NAME varchar(255) NOT NULL,
EVE_CORP_ID int(11) NOT NULL,
EVE_CORP_NAME varchar(255) NOT NULL,
EVE_ALLIANCE_NAME varchar(255) DEFAULT NULL,
PRIMARY KEY (ID_CHARACTER))", __FILE__, __LINE__);

// Rules table
db_query("CREATE TABLE IF NOT EXISTS {$db_prefix}eve_settings(
ID_SET int(11) NOT NULL auto_increment,
ID_MEMBER mediumint(8) unsigned DEFAULT NULL,
NAME varchar(30) NOT NULL,
VALUE mediumint(4) NOT NULL,
PRIMARY KEY (ID_SET))", __FILE__, __LINE__);

// Populate alliance table
fillAllianceData();

?>
